<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        html:active {
            background-color: red;
        }
    </style>
</head>
<body>

    <script>
        // 1. 高仿fn
        // 2. 记timer
        function throttle(fn, time) {
            let timer = null;

            return function (...args) {
                if (timer) {
                    return;
                }
                fn.apply(this, args);
                timer && clearTimeout(timer);
                timer = setTimeout(() => {
                    timer = null;
                }, time);
            };
        }

        function f1(e) {
            console.log(1);
        }

        const f2 = throttle(f1, 2000);

        document.addEventListener('click', f2);

    </script>
</body>
</html>
